package com.itheima.com.单列模式;

import java.io.Serializable;

//双检锁懒汉式
public class Singleton2 implements Serializable {

    private Singleton2() {
        System.out.println("private Singleton4()");
    }

    private static volatile Singleton2 INSTANCE = null; // 可见性，有序性

    public static Singleton2 getInstance() {
        if (INSTANCE == null) {
            synchronized (Singleton2.class) {
                if (INSTANCE == null) {
                    INSTANCE = new Singleton2();
                }
            }
        }
        return INSTANCE;
    }
}
